<template>
	<view class="content">
		<view class="cplist">
			<view>
				<image :src="imgoss+detail.pic" mode="aspectFill" class="zrimg"></image>
				<view>
					<view>{{detail.name}}</view>
					<view><span>￥</span>{{detail.money}}</view>
				</view>
			</view>
		</view>
		<view class="conlist">
			<view class="iptxt">
				<view>数量</view>
				<view>
					<u-number-box v-model="value" @change="valChange"></u-number-box>
				</view>
			</view>
			<view class="iptxt">
				<view>体验时间</view>
				<view class="iptxt1" @tap="show = true">
					<span :style="date?'color:#333':''">{{date?date:'请选择'}}</span>
					<image src="/static/newr.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<view class="conlist">
			<!-- <view class="iptxt">
				<view>联系人</view>
				<view>
					<input type="text" v-model="name" placeholder="请输入联系人" />
				</view>
			</view> -->
			<view class="iptxt">
				<view>联系电话</view>
				<view>
					<input type="number" maxlength="11" v-model="mobile"  placeholder="请输入联系电话" />
				</view>
			</view>
		</view>
		<view class="conlist1">
			<view>备注<span style="color:red">（选填）</span></view>
			<view>
				<textarea v-model="info" maxlength="60" placeholder="请输入"></textarea>
				<view>{{info.length}}/60</view>
			</view>
		</view>

		<view class="conlist2">
			<view>价格明细</view>
			<view class="iptxt2">
				<view>商品总价</view>
				<view>
					<span>￥{{detail.money*value}}</span>
				</view>
			</view>
			<view class="iptxt2" @tap="show1 = true">
				<view>优惠券</view>
				<view>
					<span style="color: #D9688E ;">-￥{{price}}</span>
					<image src="/static/rzicon.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="iptxt2">
				<view>合计</view>
				<view>
					<span>￥{{(detail.money*value-price*1).toFixed(2)}}</span>
				</view>
			</view>
		</view>
		<view class="btnfor">
			<view>合计<span>￥{{(detail.money*value-price*1).toFixed(2)}}</span></view>
			<view @tap="save">立即支付</view>
		</view>

		<u-popup v-model="show1" :mask="true" :closeable='true' mode="bottom" width="100%" border-radius="40"
			height="auto" @close="onClose">
			<view class="phonecon">
				<view class="txt">优惠卷</view>
				<scroll-view :scroll-y="true" class="yhlists">
					<view class="yhlist" v-for="(item,index) in list" :key="index">
						<view>
							<view class="txt1">
								<span>{{item.jian_price}}元</span>
								<span>满{{item.man_price}}可用</span>
							</view>
							<view class="txt2">
								<view>{{item.name}}</view>
								<view>{{item.start_time}}-{{item.end_time}}</view>
							</view>
						</view>
						<view class="xzimg" @tap="swidths(index)">
							<image :src="item.checks?'/static/wxicon2.png':'/static/wxicon1.png'" mode="widthFix">
							</image>
						</view>
					</view>
				</scroll-view>
			</view>
		</u-popup>
		<u-picker mode="time" v-model="show" :params="params" @confirm="confirms"></u-picker>
		<view class="weixin-tip" v-if="checks==true" @tap="checks = !checks">
			<image src="/static/llq.png" mode="widthFix">
		</view>
	</view>
</template>

<script>
	const app = getApp();
	var util = require('../../utils/util.js');
	export default {
		components: {},
		data() {
			return {
				imgoss: app.globalData.imgoss,
				show: false,
				show1: false,
				params: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				date: util.currentdate(),
				value: 1,
				img_src: app.globalData.img_src,
				img_url: app.globalData.img_urls,
				id: '',
				shop_id: '',
				detail: '',
				user_coupon_id: '',
				list: [],
				price: 0,
				name: '',
				mobile: '',
				info: '',
				checks: false,
				user:""
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onLoad(options) {
			var that = this;
			this.id = options.id;
			this.shop_id = options.shop_id
			this.Usermy()
			this.IndexshopDes()
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
			if (uni.getStorageSync('paytype') == 1) {
				uni.showToast({
					title: '已取消了支付~',
					icon: 'none',
					duration: 2000,
					success: function() {
						setTimeout(function() {
							uni.redirectTo({
								url: '/pages/order/order'
							})
						}, 1000);
					}
				});
			}
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {},
		methods: {
			Usermy(){
				const that =this;
				app.globalData.api.request('User/my', {}, 'post', 'form').then((res) => {
					if (res.code == 0) {
						that.user = res.data.user;
						this.mobile = res.data.user.mobile?res.data.user.mobile:''
					}else{
						app.globalData.show(res.msg)
					}
				});
			},
			save() {
				if (this.date == '') {
					app.globalData.show('请选择时间~')
					return true
				}
				// if (this.name == '') {
				// 	app.globalData.show('请输入联系人~')
				// 	return true
				// }
				if (this.mobile == '') {
					app.globalData.show('请输入手机号~')
					return true
				}
				if (this.mobile.length < 11) {
					app.globalData.show('手机号格式不正确~')
					return true
				}
				const that = this;
			
				// console.log(requestData);
				app.globalData.api.request('User/orderSubmit', {
					goods_id: this.id,
					number: this.value,
					order_time: this.date,
					name: this.name,
					user_name: this.name,
					info: this.info,
					mobile: this.mobile,
					money: that.detail.money * this.value,
					pay_money: that.detail.money * this.value,
					user_coupon_id: this.user_coupon_id,
				}, 'post', 'form').then((res) => {
					if (res.code == 0) {
						uni.navigateTo({
							url: `/pages/paycenter/paycenter?orderNumber=${res.data.order_number}&price=${(that.detail.money * this.value-that.price*1).toFixed(2)}`
						})
						// if(util.isWechat()==true){
							
						// }else{
						// 	console.log(res.data)
						// 	this.orderPayByOrderNumber(res.data.order_number)
						// }
					} else {
						if (res.msg == '亲登陆') {
							wx.navigateTo({
								url: "/pages/login/index"
							})
						}
					}
				});
			},
			orderPayByOrderNumber(order_number) {
				const that = this;
				// User/orderPayByOrderNumber
				app.globalData.api.request('User/orderAliByOrderNumber', {
					order_number: order_number
				}, 'post', 'form').then((res) => {
					if (res.code == 0) {
						// #ifdef H5
						if (util.isWechat() == true) {
							this.checks = true
							uni.setClipboardData({
								data: res.data,
								success: function() {}
							});
						} else {
							this.checks = false
							uni.setStorageSync('paytype', 1)
							window.open(res.data, '_self');
						}
						// #endif
					} else {
						app.globalData.show(res.msg)
					}
				});
			},
			IndexshopDes() {
				const that = this;
				app.globalData.api.request('Index/goodsDes', {
					id: this.id
				}, 'post', 'form').then((res) => {
					if (res.code == 0) {
						that.detail = res.data;
					} else {
						app.globalData.show(res.msg)
					}
				});
				app.globalData.api.request('User/userCoupon', {
					status: 1
				}, 'post', 'form').then((res) => {
					if (res.code == 0) {
						//console.log(res)
						res.data.forEach(function(item, index) {
							item.checks = false
						})
						that.list = res.data;
					} else {
						app.globalData.show(res.msg)
					}
				});

			},
			swidths(idx) {
				var that = this
				this.list.forEach(function(item, index) {
					if (idx == index) {
						item.checks = true
						that.user_coupon_id = item.id
						that.price = item.jian_price
					} else {
						item.checks = false
					}
				})
				this.show1 = false
			},
			onClose() {
				this.show1 = false
			},
			confirms(e) {
				//console.log(e)
				this.date = e.year + '-' + e.month + '-' + e.day
			},
			valChange(e) {
				//console.log('当前值为: ' + e.value)
			},
		}
	};
</script>
<style lang="scss">
	.xzimg {
		width: 80rpx;
		height: 154rpx;
		position: absolute;
		top: 0px;
		right: 0px;
		display: inline-flex;
		justify-content: center;
		align-items: center;
	}

	.xzimg>image {
		width: 20px;
		height: auto;
	}

	.txt2 {
		width: 381rpx;
		height: 154rpx;
		display: flex;
		float: right;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.txt2>view {
		width: 100%;
		height: auto;
		display: table;
	}

	.txt2>view:nth-child(1) {
		color: rgba(255, 255, 255, 1);
		font-size: 28rpx;
		text-align: left;
		font-family: PingFangSC-regular;
		margin-bottom: 10rpx;
	}

	.txt2>view:nth-child(2) {
		color: rgba(255, 255, 255, 1);
		font-size: 24rpx;
		text-align: left;
		font-family: PingFangSC-regular;
	}

	.txt1 {
		width: 189rpx;
		height: 154rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		float: left;
	}

	.txt1>span:nth-child(1) {
		color: rgba(255, 255, 255, 1);
		font-size: 42rpx;
		text-align: left;
		font-family: PingFangSC-regular;
		margin-bottom: 5px;
	}

	.txt1>span:nth-child(2) {
		border-radius: 50px;
		background-color: rgba(255, 255, 255, 1);
		color: rgba(134, 101, 175, 1);
		font-size: 24rpx;
		padding: 0px 20rpx;
		text-align: center;
		box-shadow: 0px 2px 6px 0px rgba(134, 101, 175, 1);
		font-family: Roboto;
	}

	.yhlist>view:nth-child(1) {
		width: 601rpx;
		height: 154rpx;
		background: url($IMG_URL+'yhimg.png')no-repeat;
		background-size: 100% 100%;
	}

	.yhlist {
		width: 100%;
		height: 154rpx;
		margin-bottom: 30rpx;
		position: relative;
		box-sizing: border-box;
		padding-right: 60rpx;
		position: relative;
	}

	.yhlists {
		width: 100%;
		max-height: 600rpx;
		display: block;
		overflow: hidden;
		margin-top: 30rpx;
	}

	.txt {
		width: 100%;
		height: auto;
		display: table;
		color: rgba(16, 16, 16, 1);
		font-size: 28rpx;
		text-align: left;
		font-family: PingFangSC-medium;
	}

	.phonecon {
		width: 100%;
		height: auto;
		display: table;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.btnfor {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		padding: 20rpx 24rpx;
		position: fixed;
		left: 0px;
		bottom: 0px;
		z-index: 10;
		background-color: #fff;
	}

	.btnfor>view:nth-child(1) {
		float: left;
		color: rgb(0, 0, 0);
		font-size: 28rpx;
		text-align: left;
		font-family: PingFangSC-medium;
	}

	.btnfor>view:nth-child(2) {
		float: right;
		border-radius: 10rpx;
		background-color: rgba(134, 101, 175, 1);
		color: rgba(255, 255, 255, 1);
		font-size: 24rpx;
		text-align: center;
		font-family: Roboto;
		line-height: 60rpx;
		padding: 0px 40rpx;
	}

	.btnfor>view:nth-child(1)>span {
		color: #D9688E !important;
	}

	.content {
		padding-bottom: 140rpx;
	}

	.iptxt2 {
		width: 100%;
		height: 80rpx;
		display: inline-flex;
		justify-content: space-between;
	}

	.iptxt2>view:nth-child(1) {
		color: rgb(0, 0, 0);
		font-size: 25rpx;
		text-align: left;
		float: left;
		width: auto;
		line-height: 80rpx;
		display: inline-block;
		font-family: PingFangSC-medium;
	}

	.iptxt2>view:nth-child(2) {
		color: rgb(0, 0, 0);
		font-size: 25rpx;
		text-align: left;
		width: auto;
		float: right;
		font-family: PingFangSC-medium;
		display: inline-flex;
		justify-content: center;
		align-items: center;
		height: 80rpx;
	}

	.iptxt2>view:nth-child(2)>image {
		width: 16px;
		margin-left: 10rpx;
	}

	.conlist2>view:nth-child(1) {
		color: rgb(0, 0, 0);
		font-size: 25rpx;
		text-align: left;
		font-family: PingFangSC-medium;
		width: 100%;
		line-height: 40px;
	}

	.conlist2 {
		width: 100%;
		height: auto;
		display: table;
		margin-bottom: 10rpx;
		box-sizing: border-box;
		padding: 0px 24rpx;
		background-color: #fff;
	}

	.conlist1>view:nth-child(2) {
		width: 100%;
		height: 200rpx;
		position: relative;
		margin-bottom: 20rpx;
	}

	.conlist1>view:nth-child(2)>textarea {
		width: 100%;
		height: 200rpx;
		border-radius: 10px;
		background-color: rgba(248, 248, 248, 1);
		color: rgba(16, 16, 16, 1);
		font-size: 14px;
		font-family: Roboto;
		box-sizing: border-box;
		padding: 20rpx;
	}

	.conlist1>view:nth-child(2)>view {
		position: absolute;
		right: 20rpx;
		bottom: 20rpx;
		color: rgb(16, 16, 16);
		font-size: 24rpx;
		text-align: left;
		font-family: SourceHanSansSC-regular;
	}

	.conlist1>view:nth-child(1) {
		color: rgb(0, 0, 0);
		font-size: 25rpx;
		text-align: left;
		font-family: PingFangSC-medium;
		width: 100%;
		line-height: 40px;
	}

	.conlist1 {
		width: 100%;
		height: auto;
		display: table;
		margin-bottom: 10rpx;
		box-sizing: border-box;
		padding: 0px 24rpx;
		background-color: #fff;
	}

	.iptxt>view:nth-child(2)>input {
		width: 300rpx;
		text-align: right;
		font-size: 24rpx;
		color: #333;
	}

	.iptxt>view:nth-child(1) {
		width: auto;
		height: 94rpx;
		line-height: 94rpx;
		display: inline-block;
		float: left;
		color: rgb(0, 0, 0);
		font-size: 25rpx;
		text-align: left;
		font-family: PingFangSC-medium;
	}

	.iptxt>view:nth-child(2) {
		width: auto;
		height: 94rpx;
		line-height: 94rpx;
		display: inline-flex;
		align-items: center;
		float: right;
	}

	.iptxt1 {
		color: rgba(151, 151, 150, 1);
		font-size: 25rpx;
		margin-right: 15rpx;
		text-align: left;
		font-family: PingFangSC-regular;
	}

	.iptxt1>image {
		width: 28rpx;
	}

	.conlist {
		width: 100%;
		height: auto;
		display: table;
		margin-bottom: 10rpx;
		box-sizing: border-box;
		padding: 0px 24rpx;
		background-color: #fff;
	}

	.conlist>view {
		width: 100%;
		height: 94rpx;
		border-bottom: 1px solid rgba(245, 245, 245, 0.5);
	}

	page {
		background-color: rgba(245, 245, 245, 1);
	}

	.cplist>view>view {
		width: 100%;
		min-height: 160rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		position: relative;
	}

	.cplist>view>view>view {
		width: 100%;
		height: auto;
		display: table;
	}

	.cplist>view>view>view:nth-child(1) {
		color: rgba(16, 16, 16, 1);
		font-size: 28rpx;
		text-align: left;
		font-weight: bold;
		line-height: 25px;
		font-family: PingFangSC-regular;
	}

	.cplist>view>view>view:nth-child(2) {
		color: rgba(217, 104, 142, 1);
		font-size: 28rpx;
		text-align: left;
		margin-top: 10rpx;
		line-height: 25px;
		font-family: PingFangSC-regular;
	}

	.cplist>view>view>view:nth-child(2)>span {
		font-size: 24rpx !important;
	}

	.zrimg {
		width: 160rpx;
		height: 160rpx;
		border-radius: 10rpx;
		position: absolute;
		top: 20rpx;
		left: 0rpx;
	}

	.cplist {
		width: 100%;
		height: auto;
		display: table;
		box-sizing: border-box;
		padding: 0rpx 24rpx;
		background-color: #fff;
		margin-bottom: 10rpx;
	}

	.cplist>view {
		width: 100%;
		min-height: 200rpx;
		display: table;
		box-sizing: border-box;
		padding: 20rpx 0rpx;
		box-sizing: border-box;
		padding-left: 180rpx;
		position: relative;
	}

	.shopcon {
		width: 100%;
		height: auto;
	}
</style>